<?php
function get_point($num)
{
    switch($num)
    {
        case 0:
            return '淮工';
        case 1:
            return '月季花园';
        case 2:
            return '大运河桥';
        case 3:
            return '联盛广场';
        case 4:
            return '淮海广场';
    }
    return false;
}
?>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8"/>
    <title>拼车系统</title>
    <link rel="stylesheet" href="<?php echo base_url('bootstrap/css/bootstrap.css'); ?>">
    <link rel="stylesheet" href="<?php echo base_url('bootstrap/css/bootstrap-theme.css'); ?>">
    <link rel="stylesheet" href="<?php echo base_url('bootstrap/css/bootstrap-datetimepicker.css'); ?>">
    <link rel="stylesheet" href="<?php echo base_url('css/style.css') ?>">
</head>
<body>
<nav class="navbar navbar-inverse" id="navbar-top">
    <div id="div-top">
        <div class="navbar-header">
            <a class="navbar-brand navbar-h" href="<?php echo site_url('/info') ?>">
                <img src="<?php echo base_url('image/logo.png'); ?>">
            </a>
        </div>
        <div class="collapse navbar-collapse">
            <ul class='nav nav-pills nav-self'>
                <?php
                $signup=site_url('user/signup');
                $signin=site_url('user/signin');
                $create=site_url('info/create');
                $manage=site_url('info/manage');
                $signout=site_url('user/signout');
                $name=$this->session->userdata('username');
                if(!$this->session->userdata('login'))
                {
                    echo "<li><a href='$signup'>注册</a></li>".
                        "<li><a href='$signin'>登录</a></li>";
                }
                else
                {
                    echo "<li><span class='navbar-text navbar-right'>欢迎 $name</span></li>".
                        "<li><a href='#'>用户中心</a></li>".
                        "<li><a href='$manage'>订单管理</a></li>".
                        "<li><a href='$signout'>注销</a></li>";
                }
                ?>
            </ul>
        </div>
    </div>
</nav>
<div class="container" id="page">
    <?php if($dsell!=NULL): ?>
        <h5>作为车主</h5>
    <table class="table table-striped">
        <thead>
        <tr>
            <th>乘客</th>
            <th>起点</th>
            <th>终点</th>
            <th>价格</th>
            <th>时间</th>
            <th></th>
        </tr>
        </thead>
        <tbody>
        <?php foreach($dsell as $row): ?>
            <tr>
                <td><?php echo $row['USER_NAME']; ?></td>
                <td><?php echo get_point($row['BEGIN_POINT']); ?></td>
                <td><?php echo get_point($row['END_POINT']); ?></td>
                <td><?php echo $row['PRICE']; ?></td>
                <td><?php echo $row['U_TIME']; ?></td>
                <td><a href="<?php echo site_url('info/confirm').'/'.$row['ORDER_ID']; ?>">确认</a></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    <?php endif; ?>
    <?php if($dbuy!=NULL): ?>
        <h5>作为乘客</h5>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>车主</th>
                <th>起点</th>
                <th>终点</th>
                <th>价格</th>
                <th>时间</th>
                <th>已加入/可容纳</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($dbuy as $row): ?>
                <tr>
                    <td><?php echo $row['USER_NAME']; ?></td>
                    <td><?php echo get_point($row['BEGIN_POINT']); ?></td>
                    <td><?php echo get_point($row['END_POINT']); ?></td>
                    <td><?php echo $row['PRICE']; ?></td>
                    <td><?php echo $row['U_TIME']; ?></td>
                    <td><?php echo $row['CURRENT_NUM'].'/'.$row['MAX_NUM']; ?></td>
                    <td><a href="<?php echo site_url('info/confirm').'/'.$row['ORDER_ID']; ?>">确认</a></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>
    <?php if($dfinish!=NULL): ?>
        <h5>待评价</h5>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>起点</th>
                <th>终点</th>
                <th>价格</th>
                <th>时间</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($dfinish as $row): ?>
                <tr>
                    <td><?php echo get_point($row['BEGIN_POINT']); ?></td>
                    <td><?php echo get_point($row['END_POINT']); ?></td>
                    <td><?php echo $row['PRICE']; ?></td>
                    <td><?php echo $row['U_TIME']; ?></td>
                    <td>
                        <button class="btn btn-primary btn-sm comment" data-orderid="<?php
                        echo $row['ORDER_ID']; ?>" data-userid1="<?php echo $row['USER_ID_B']; ?>"
                                data-userid2="<?php echo $row['USER_ID_S']; ?>" data-toggle="modal" data-target="#myModal">
                            评价
                        </button>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">评论</h4>
            </div>
            <div class="modal-body">
                ...
            </div>
            <div class="modal-footer">
                <form id="form-comment">
                    <textarea id="content" name="content" class="form-control"></textarea>
                    <button id="submit" type="button" class="btn btn-default">提交评论</button>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="<?php echo base_url('js/jquery-2.1.1.js'); ?>"></script>
<script src="<?php echo base_url('bootstrap/js/bootstrap.js'); ?>"></script>
<script src="<?php echo base_url('bootstrap/js/bootstrap-datetimepicker.js'); ?>"></script>
<script src="<?php echo base_url('bootstrap/js/locales/bootstrap-datetimepicker.zh-CN.js'); ?>"></script>
<script>
    var orderid;
    var userid1;
    var userid2;
    $(".comment").click(function(event){
        orderid=$(event.target).attr("data-orderid");
        userid1=$(event.target).attr("data-userid1");
        userid2=$(event.target).attr("data-userid2");
        $(".modal-body").html("加载中...");
        $.ajax({
            cache:true,
            type:'get',
            url:"<?php echo site_url('info/comment'); ?>",
            data:"orderid="+orderid+"&userid1="+userid1+"&userid2="+userid2,
            error:function(){},
            success:function(data){
                if(data=='') {$(".modal-body").html("暂无评论");}
                else {$(".modal-body").html(data);}
            }
        });
    });
    $("#submit").click(function(){
        var t=$("#content");
        $.ajax({
            cache:true,
            type:'post',
            url:"<?php echo site_url('info/new_comment'); ?>",
            data:"orderid="+orderid+"&userid1="+userid1+"&userid2="+userid2+"&content="+t.val(),
            error:function(){},
            success:function(data){
                $(".modal-body").html(data);
            }
        });
        t.val("");
    });
</script>
</body>
</html>